using System;
using System.Configuration;
using System.Collections.Generic;
using System.Text;
using BA.DAL;

namespace BlazeApps.Library
{
    public class ConfigSettings
    {
        #region private and public members

        #endregion

        #region properties

        public string ConnectionString
        {
            get
            {
                if(String.IsNullOrEmpty(ConfigurationManager.ConnectionStrings["BlazeApps"].ToString()))
                {
                    throw new ConfigurationErrorsException("The connection string is missing from the web config file.  Add a valid connection string to the connectionStrings section.");
                }
                else
                {
                    return ConfigurationManager.ConnectionStrings["BlazeApps"].ToString();
                }
            }
        }

        public DBUtility.Providers Provider
        {
            get
            {
                if (String.IsNullOrEmpty(ConfigurationManager.ConnectionStrings["BlazeApps"].ProviderName.ToString()))
                {
                    if (String.IsNullOrEmpty(ConfigurationManager.AppSettings["DBProvider"].ToString()))
                    {
                        throw new ConfigurationErrorsException("The DBProvider information is missing from the web config file in the appSettings section.  Add a providerName entry to the connection string entry to correct this error.");
                    }
                    else
                    {
                        return (DBUtility.Providers)System.Enum.Parse(typeof(DBUtility.Providers), ConfigurationManager.AppSettings["DBProvider"].ToString().Trim(), true); ;
                    }
                }
                else
                {
                    if (String.IsNullOrEmpty(ConfigurationManager.ConnectionStrings["BlazeApps"].ProviderName.ToString()))
                    {
                        throw new ConfigurationErrorsException("The providerName information is missing from the web config file on the connection string entry..  Add a providerName entry to the connection string entry to correct this error.");
                    }
                    else
                    {
                        return (DBUtility.Providers)System.Enum.Parse(typeof(DBUtility.Providers), ConfigurationManager.ConnectionStrings["BlazeApps"].ProviderName.ToString().Trim(), true); ;
                    }
                }
            }
        }

        #endregion
    }
}
